package com.ktjy.market;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ktjy.market.mapper.AppInfoMapper;
import com.ktjy.market.mapper.DevUserMapper;
import com.ktjy.market.pojo.AppInfo;
import com.ktjy.market.pojo.DevUser;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Arrays;
import java.util.List;

public class Tests {

    @Test
    public void pageHelper() {
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext-jdbc.xml");
        AppInfoMapper appInfoMapper=
                (AppInfoMapper) context.getBean("appInfoMapper");
        PageHelper.startPage(1,5);//设置分页信息，第一天，每页5条
       AppInfo appInfo=new AppInfo();
        //设置完分页信息后，进行查询
        List<AppInfo> appInfos=appInfoMapper.getAppInfoList(appInfo);
        PageInfo<AppInfo> page = new PageInfo<>(appInfos);
        //共条 记录   /页
        System.out.println("共"+ page.getPages() + "页");
        System.out.println("共"+ page.getTotal() + "条");
        System.out.println("当前第"+ page.getPageNum() + "页");
        System.out.println("首页:"+ page.getNavigateFirstPage());
        System.out.println("尾页:"+ page.getNavigateLastPage());
        //Arrays  ---[]
        //ArrayList  ---集合
        System.out.println("页码数: "+ Arrays.toString( page.getNavigatepageNums()));
        System.out.println("数据列表: :" );
        page.getList().forEach(System.out::println);
    }

}
